package com.atguigu.gmall.task.task0;

import com.atguigu.gmall.rabbit.constant.MqConst;
import com.atguigu.gmall.rabbit.service.RabbitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自定义秒杀任务
 */
@Component
@EnableScheduling//开启定时器任务
public class SeckillTask {

    @Autowired
    private RabbitService rabbitService;

    //定时器
    //cron表达式（定时器的表达式，定时用的）
    //@Scheduled(cron = "0 0 0 * * ? ")//每天半夜0点执行
    //@Scheduled(cron = "0 0/1 * * * ? ")//每隔一分钟执行一次
    @Scheduled(cron = "0/30 * * * * ?")//每隔30秒执行一次
    public void task0(){
        System.out.println(new Date());

        //发消息给MQ，让mq来监督其他微服务完成，不手动应答，MQ最终一致性
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK,
                MqConst.ROUTING_TASK_1,"");

    }


}

